package com.itbaizhan.openhis.controller;


import com.itbaizhan.openhis.domain.VerificationCode;
import com.itbaizhan.openhis.service.VerificationCodeService;
import com.itbaizhan.openhis.vo.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/sms")
@RestController
public class SmsController {

    @Autowired
    private VerificationCodeService verificationCodeService;

    /**
     * 发送短信
     *
     * @param phoneNumber 手机号
     * @return
     */
    @GetMapping("/send")
    public AjaxResult sendSms(@RequestParam(name = "phoneNumber") String phoneNumber) {
        return AjaxResult.success(verificationCodeService.sendSms(phoneNumber));
    }

    /**
     * 验证短信
     *
     * @param phoneNumber 手机号
     * @param code        验证码
     * @return
     */
    @GetMapping("/check")
    public AjaxResult checkCode(@RequestParam(name = "phoneNumber") String phoneNumber, @RequestParam(name = "code")Integer code) {
        return AjaxResult.success(verificationCodeService.checkCode(phoneNumber,code));
    }

}
